package ebj.common.annotation.demo_data_provider_manager.data_provider;

import java.util.Map;

import ebj.common.annotation.demo_data_provider_manager.anno.ProviderAttribute;
import ebj.common.annotation.demo_data_provider_manager.anno.ProviderAttribute.AttributeType;
import ebj.common.annotation.demo_data_provider_manager.anno.ProviderName;
import ebj.common.annotation.demo_data_provider_manager.anno.QueryParameter;
import ebj.common.annotation.demo_data_provider_manager.anno.QueryParameter.Type;

@ProviderName("demo")
public class DemoDataProvider extends DataProvider {
    // **数据源管理** 页面 创建数据源的时候需要配置的参数
    @ProviderAttribute(name = "数据源参数", type = AttributeType.Input, defaultValue="参数", order = 1)
    private String DS_PARAM_KEY = "param";
    // **图表设计**页面 读取数据接收参数
    @QueryParameter(name = "查询参数", type=Type.Input, order = 2)
    private String QUERY_PARAM_KEY = "queryParam";
    
    @Override
    public String[][] getData(Map<String, String> datasourceConfig,
            Map<String, String> query) throws Exception {
        // 获取data source 参数创建数据连接
        String param = datasourceConfig.get(DS_PARAM_KEY);
        // TODO 利用接收到的DataSource配置参数创建DataSource连接，如：JDBC Connection，这个演示从内存返回数据，就不用创建连接了

        // 查询获取数据
        String queryParam = query.get(QUERY_PARAM_KEY);
        System.out.println(queryParam);
        // 表头
        String[] header = {"D1", "D2", "D3", "M1", "M2"};
        String[] header2 = {"Dim1", "Dim2", "Dim3", "Metrics1", "Metrics2"};
        String[][] result = {
                "1".equals(queryParam) ? header : header2, // 第一行返回表头, 这里演示怎么和配置的查询前端参数交互切换表头
                {queryParam, "b1", "c1", "1", "2"},
                {queryParam, "b2", "c2", "13", "42"},
                {queryParam, "b3", "c3", "781", "52"},
                {queryParam, "b4", "c4", "17", "92"}
        };
        return result;
    }
}
